<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<%@include file="/common/include_all.jsp"%>
<script type="text/javascript" src="${contextPath}/js/crawler.js"></script>
<c:set var="contextPath" value="${pageContext.request.contextPath}" scope="application" />
<script type="text/javascript">
var contextPath = "${contextPath }"; 
$(function(){
	var frozenColumns = [[{field : 'id',title : '编号',width : 60,checkbox : false,hidden:true, halign:'center'}]];
	var columns = [[
				  {field : 'loginName',title : '登陆名',width : 100,halign:'center',align:'left'},
				  {field : 'realName',title : '真实名',width : 100,halign:'center',align:'left'},
				  {field : 'email',title : '邮件',width : 100,halign:'center',align:'left'},
				  {field : 'gradeLevel',title : '荣誉等级',width : 60,halign:'center',align:'left'},
				  {field : 'gradeType',title : '荣誉类型',width : 60,halign:'center',align:'left'},
				  //{field : 'mobile',title : '手机号',width : 60,halign:'center',align:'left'},
				  //{field : 'shopLevel',title : '购物等级',width : 100,halign:'center',align:'left'},
				 // {field : 'registerTime',title : '注册时间',width : 100,halign:'center',align:'left'}
				  ]];
	var dg = jfinal.datagrid('dg_${timer }', '${contextPath }/jdAccount', 'tb_${timer }', frozenColumns, columns);
	dg.datagrid({
		onClickRow:onClickRow
	});
});

function fetch(){
	var username = $("#username_${timer }").val();
	var password = $("#password_${timer }").val();
	if(isBlank(username) || isBlank(password)){
		jfinal.easyAlert("username or password is blank！");
	}else{
		var url = '${contextPath }/crawler/fetch';
		var params = {};
		params.username = username;
		params.password = password;
		params.op = '3';
		jfinal.showProcess("正在获取验证码");
		jfinal.ajaxPost(url, params, function(data){
			jfinal.closeProgress();
			if(data.flag == true){
				showCheckCodeDlg(data.checkCodeImg);
			}else{
				jfinal.easyAlert(data.error);
			}
		});
	}
}
/**
 * 验证码对话框
 * */
function showCheckCodeDlg(base64ImgStr){
	if(base64ImgStr != null){
		$("#checkCode_${timer}").val("");
		$("#imgCheckCode_${timer }").attr("src", "data:image/jpg;base64," + base64ImgStr);
	}
	$("#divCheckCode_${timer}").show();
	$('#divCheckCode_${timer}').dialog({
		title : '验证码',
		maximizable : true,
		width : 250,
		modal : true
	}).dialog('open').error(function() {
		$.messager.progress('close');
		$.messager.alert('登录错误', '获取验证码图片失败！', 'error');
	});
}
function doLoginBycheckCode(){
	var username = $("#username_${timer }").val();
	var password = $("#password_${timer }").val();
	var url = "${contextPath }/crawler/fetch";
	var params = {};
	params.username = username;
	params.password = password;
	params.checkCode = $("#checkCode_${timer}").val();
	params.op = '3';
	jfinal.showProcess("正在登陆");
	jfinal.ajaxPost(url, params, function(data){
		jfinal.closeProgress();
		if(data.flag == true){
			$('#divCheckCode_${timer}').dialog().dialog('close');
			params.op = "4" ;
			jfinal.showProcess("正在采集数据...请耐心等待");
			jfinal.ajaxPost(url, params, function(dataT){
				jfinal.closeProgress();
				jfinal.easyAlert(dataT.operate);
				jfinal.onQuery('queryFrom_${timer }', 'dg_${timer }');
			});
		}else{
			alert(data.error);
		}
	});
}
function doRefreshCode(){
	fetch();
}
function reset(){
	$("#username_${timer }").val("");
	$("#password_${timer }").val("");
}
</script>
</head>
<body class="easyui-layout">
  <div id="site_title_bar_wrapper" region="north" style="height:100px;padding:0px">
  	<div id="site_title_bar">
	    <div id="site_title">
	        <table>
	        <tr>
	        	<td>
	        	<span>
		    		<img src="" />
	        	</span>
	        	</td>
	        	<td>
	        	<span style="margin-bottom:3px;">
		            <a href="javascript:void(0)"></a>
	        	</span>
	        	</td>
	        </tr>
	        </table>
	     </div>
	 </div>
  </div>
  <div region="west" id="west" style="width:70%;padding:0px" title="订单信息">
 	 <table id="dg_orderInfo"></table>
  </div>
  <div region="center" title="操作区" >
	  <table id="dg_${timer }"></table>
  </div>

<!-- tool bar -->
<div id="tb_${timer }">
	<div id="tb" style="padding:5px;height:auto">
       <div style="margin-bottom:5px">
       <form id="inputFrom_${timer }" action="">
       <table style="border: solid #000 1px; width: 100%">
       	<tr>
			<td style="text-align:right;">
				用户名:
			</td>
			<td style="text-align:left;">
				<input class="easyui-validatebox" name="username" id="username_${timer }" />
			</td>
       	</tr>
       	<tr>
			<td style="text-align:right;">
				密码:
			</td>
			<td style="text-align:left;">
				<input class="easyui-validatebox" type="password"  name="password" id="password_${timer }" />
			</td>
       	</tr>
       	<tr>
			<td style="text-align:right;">
			</td>
			<td style="text-align:left;">
				<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="fetch()" >登陆</a>
				<a href="#" class="easyui-linkbutton" iconCls="icon-reload" onclick="reset()" >重置</a>
			</td>
       	</tr>
       </table>
       </form>
       </div>
       <div style="margin-bottom:5px">
        <form id="queryFrom_${timer }" action="">
        	查询条件: <input class="easyui-validatebox" style="width: 100px;" name="loginName_string_like" />
            <a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="jfinal.onQuery('queryFrom_${timer }', 'dg_${timer }')" >查询</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-reload" onclick="jfinal.onReset('queryFrom_${timer }', 'dg_${timer }')" >重置</a>
	     </form>
	    </div>
    </div>
</div>
  
<!-- 输入验证码窗口 -->
<div id = "divCheckCode_${timer}" style="display: none">
	<form id="f_checkCode_${timer}">
		<table>
			<tr>
				<td>验证码：</td>
				<td><input type="text" id="checkCode_${timer}" name="checkCode"/></td>
			</tr>
			<tr>
				<td>图片:</td>
				<td><img src="#" id="imgCheckCode_${timer }" name="imgCheckCode" alt="点击刷新" onclick="javascript:doRefreshCode()"/></td>
			</tr>
			<tr>
				<td><input type="button" value="提交" onclick="javascript:doLoginBycheckCode()"/></td>
			</tr>
		</table>
	</form>
</div>

</body>
</html>